package com.anti.modular.bus.billrentadjustment.controller;

import com.anti.commom.annotation.BusinessLog;
import com.anti.commom.annotation.Permission;
import com.anti.commom.enums.LogAnnotionOpTypeEnum;
import com.anti.commom.api.Result;
import com.anti.jdbc.support.page.PageParam;
import com.anti.modular.bus.billrentadjustment.param.BillRentAdjustmentParam;
import com.anti.modular.bus.billrentadjustment.service.BillRentAdjustmentService;
import org.springframework.web.bind.annotation.*;
import org.springframework.validation.annotation.Validated;

import javax.annotation.Resource;

/**
 * 租金调整记录控制器
 *
 * @author anti
 * @date 2021-05-10 14:46:45
 */
@RestController
@RequestMapping("billRentAdjustment")
public class BillRentAdjustmentController {

    @Resource
    private BillRentAdjustmentService billRentAdjustmentService;

    /**
     * 查询租金调整记录
     *
     * @author anti
     * @date 2021-05-10 14:46:45
     */
    @GetMapping("page")
    public Result page(PageParam pageParam, BillRentAdjustmentParam billRentAdjustmentParam) {
        return Result.data(billRentAdjustmentService.page(pageParam,billRentAdjustmentParam));
    }

    /**
     * 添加租金调整记录
     *
     * @author anti
     * @date 2021-05-10 14:46:45
     */
    @PostMapping("add")
    @BusinessLog(title = "租金调整记录_增加", opType = LogAnnotionOpTypeEnum.ADD)
    public Result add(@RequestBody @Validated(BillRentAdjustmentParam.add.class) BillRentAdjustmentParam billRentAdjustmentParam) {
            billRentAdjustmentService.add(billRentAdjustmentParam);
        return Result.success("新增成功");
    }

    /**
     * 删除租金调整记录
     *
     * @author anti
     * @date 2021-05-10 14:46:45
     */
    @PostMapping("delete")
    @BusinessLog(title = "租金调整记录_删除", opType = LogAnnotionOpTypeEnum.DELETE)
    public Result delete(@RequestBody @Validated(BillRentAdjustmentParam.delete.class) BillRentAdjustmentParam billRentAdjustmentParam) {
            billRentAdjustmentService.delete(billRentAdjustmentParam);
        return Result.success("删除成功");
    }

    @GetMapping("delAdjustById/{id}")
    @BusinessLog(title = "租金调整记录_删除", opType = LogAnnotionOpTypeEnum.DELETE)
    public Result delAdjustById(@PathVariable(name="id") Long id) {
        billRentAdjustmentService.deleteAdjustById(id);
        return Result.success("删除成功");
    }

    /**
     * 编辑租金调整记录
     *
     * @author anti
     * @date 2021-05-10 14:46:45
     */
    @PostMapping("edit")
    @BusinessLog(title = "租金调整记录_编辑", opType = LogAnnotionOpTypeEnum.EDIT)
    public Result edit(@RequestBody @Validated(BillRentAdjustmentParam.edit.class) BillRentAdjustmentParam billRentAdjustmentParam) {
            billRentAdjustmentService.edit(billRentAdjustmentParam);
        return Result.success("修改成功");
    }

    /**
     * 查看租金调整记录
     *
     * @author anti
     * @date 2021-05-10 14:46:45
     */
    @GetMapping("detail")
    public Result detail(@Validated(BillRentAdjustmentParam.detail.class) BillRentAdjustmentParam billRentAdjustmentParam) {
        return Result.data(billRentAdjustmentService.detail(billRentAdjustmentParam));
    }

    /**
     * 租金调整记录列表
     *
     * @author anti
     * @date 2021-05-10 14:46:45
     */
    @GetMapping("list")
    public Result list(BillRentAdjustmentParam billRentAdjustmentParam) {
        return Result.data(billRentAdjustmentService.list(billRentAdjustmentParam));
    }

    /**
     * 租金调整记录列表
     *
     * @author anti
     * @date 2021-05-10 14:46:45
     */
    @GetMapping("getAdjustmentListByLeaseId/{leaseId}")
    public Result getAdjustmentListByLeaseId(@PathVariable(name = "leaseId") Long  leaseId) {
        return Result.data(billRentAdjustmentService.getAdjustmentListByLeaseId(leaseId));
    }
}
